package com.mjl.shops.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mjl.shops.R;
import com.mjl.shops.base.ShopApp;
import com.mjl.shops.bean.CollatorRightBean;
import com.mjl.shops.utils.StringUtils;

import java.util.List;

public class CollatorRightAdapter extends BaseMultiItemQuickAdapter<CollatorRightBean, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CollatorRightAdapter(List<CollatorRightBean> data) {
        super(data);
        addItemType(CollatorRightBean.TITLE, R.layout.item_collator_right_title_layout);
        addItemType(CollatorRightBean.GOOD,R.layout.item_collator_right_goods_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, CollatorRightBean item) {

        switch (item.getItemType()){
            case CollatorRightBean.TITLE:
                if (StringUtils.strEmpty(item.getTitleName().getTitle())){
                    helper.setText(R.id.title_name_tv,item.getTitleName().getTitle());
                }else{
                    helper.setText(R.id.title_name_tv,"未知");
                }

                if (item.getTitleName().getIsAll() == 1){
                    helper.getView(R.id.look_all_tv).setVisibility(View.VISIBLE);
                }else{
                    helper.getView(R.id.look_all_tv).setVisibility(View.GONE);
                }
                break;
            case CollatorRightBean.GOOD:

                if (StringUtils.strEmpty(item.getGoods().getName())){
                    helper.setText(R.id.goods_name_tv,item.getGoods().getName());
                }else{
                    helper.setText(R.id.goods_name_tv,"未知");
                }

                if (item.getGoods().getPrice()>0){
                    helper.setText(R.id.goods_price_tv, "¥"+ ShopApp.decimalFormat.format(item.getGoods().getPrice()));
                }else{
                    helper.setText(R.id.goods_price_tv,"¥0.00");
                }

                break;
        }

    }
}
